package com.twb.core.util;

import com.twb.core.base.BaseEnum;
import com.twb.core.base.Result;

/**
 * @Title  Results
 * @Description Result生成工具类
 * @author DSY
 * @date 2018-10-17 13:45
 */
public class Results {

  protected Results() {}

  public static <T> Result<T> newResult() {
    return new Result<T>();
  }

  public static <T> Result<T> newResult(boolean success) {
    return new Result<T>(success);
  }

  //
  // 业务调用成功
  // ----------------------------------------------------------------------------------------------------
  public static <T> Result<T> success() {
    return new Result<T>();
  }

  public static <T> Result<T> success(String msg) {
    return new Result<T>(true, null, msg);
  }

  public static <T> Result<T> success(String code, String msg) {
    return new Result<T>(true, code, msg);
  }

  public static <T> Result<T> successWithStatus(Integer status) {
    return new Result<T>(true, status);
  }

  public static <T> Result<T> successWithStatus(Integer status, String msg) {
    return new Result<T>(true, status, null, msg);
  }

  public static <T> Result<T> successWithData(T data) {
    return new Result<T>(true, null, null, data);
  }

  public static <T> Result<T> successWithData(T data, String msg) {
    return new Result<T>(true, null, msg, data);
  }

  public static <T> Result<T> successWithData(T data, String code, String msg) {
    return new Result<T>(true, code, msg, data);
  }

  //
  // 业务调用失败
  // ----------------------------------------------------------------------------------------------------
  public static <T> Result<T> failure() {
    return new Result<T>(false);
  }

  public static <T> Result<T> failure(String msg) {
    return new Result<T>(false, null, msg);
  }

  public static <T> Result<T> failure(String code, String msg) {
    return new Result<T>(false, code, msg);
  }

  public static <T> Result<T> failure(BaseEnum<String, String> baseEnum) {
    return new Result<T>(false, baseEnum.code(), baseEnum.desc());
  }
  
  public static <T> Result<T> failureWithStatus(Integer status) {
    return new Result<T>(false, status);
  }

  public static <T> Result<T> failureWithStatus(Integer status, String msg) {
    return new Result<T>(false, status, null, msg);
  }

  public static <T> Result<T> failureWithData(T data) {
    return new Result<T>(false, null, null, data);
  }

  public static <T> Result<T> failureWithData(T data, String msg) {
    return new Result<T>(false, null, msg, data);
  }

  public static <T> Result<T> failureWithData(T data, String code, String msg) {
    return new Result<T>(false, code, msg, data);
  }

}